memory sugar
authorØyvind Kolås <ok@src.gnome.org>
Sun, 18 Sep 2005 20:27:37 +0000 (20:27 +0000)
committerØyvind Kolås <ok@src.gnome.org>
Sun, 18 Sep 2005 20:27:37 +0000 (20:27 +0000)
ChangeLog
babl/babl-memory.c
babl/babl-memory.h

index 14e1646ef6bc0dd4292f9a0f649b69cae1f0a9b5..20f7585a5997409bee64bb6db85c76f43d079ba2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2005-09-18  Øyvind Kolås  <pippin@gimp.org>
+
+       * babl/babl-memory.[ch]: (babl_free), (babl_realloc): made babl_free
+       variadic, and added the potential for a clearing realloc.
+
 2005-09-12  Øyvind Kolås  <pippin@gimp.org>
 
        * tests/conversions.c: (test_init): code simplification.
index b152f85d7e06c0677002f0e9245391088cedf7c2..82719aeee2e8061c754d035bae8ff42b68a36dde 100644 (file)
@@ -131,9 +131,13 @@ babl_dup (void *ptr)
 
 /* Free memory allocated by a babl function (note: babl_free
  * will complain if memory not allocated by babl is passed.)
+ *
+ * Note: the function is made variadic to be a legal callback
+ * function in some circumstances.
  */
 void
-babl_free (void *ptr)
+babl_free (void *ptr,
+           ...)
 {
   if (!ptr)
     return;
@@ -171,7 +175,15 @@ babl_realloc (void   *ptr,
     }
   else if (babl_sizeof (ptr) < size)
     {
+#ifdef USE_REALLOC_CLEAR
+      /* not needed yet by babl, if aviodable, preferred, since
+       * it has performance hits where it isn't wanted, a special
+       * function might be better when needd.
+       */
+      ret = babl_calloc (size, 1);
+#else
       ret = babl_malloc (size);
+#endif
       memcpy (ret, ptr, babl_sizeof (ptr));
       babl_free (ptr);
       reallocs++;
index 170e5662c62e4031b310d865ff5d916c6cba2c87..fbb311b37f97f799fc9b23d989b419278ad56e8a 100644 (file)
@@ -25,7 +25,8 @@ void   babl_set_free      (void      (*free)            (void   *ptr));
 int    babl_memory_sanity (void);
 
 void * babl_malloc        (size_t      size);
-void   babl_free          (void       *ptr);
+void   babl_free          (void       *ptr,
+                           ...);
 void * babl_calloc        (size_t      nmemb,
                            size_t      size);
 void * babl_realloc       (void       *ptr,